		TITLE	LDOSX	Copyright (c) SLR Systems 1994

		.MODEL	LARGE

fg_segm		EQU	-1
any_overlays	EQU	0
fg_rom		EQU	0


		.286P

		DOSSEG

		.STACK	512

		.CODE

OFFS		EQU	WORD PTR 0
SEGM		EQU	WORD PTR 2
OFF		EQU	OFFSET
WPTR		EQU	WORD PTR
BPTR		EQU	BYTE PTR
LW		EQU	WORD PTR 0
HW		EQU	WORD PTR 2

DEBMSG		MACRO	XX
		LOCAL	L1,L2
if	debug
		PUSHM	DS,DX,AX
		PUSHF
		PUSH	CS
		POP	DS
		MOV	DX,OFF L2
		MOV	AH,9
		INT	21H
		MOV	AH,1
		INT	21H
		POPF
		POPM	AX,DX,DS
		JMP	L1

;		.DATA
L2		DB	0DH,0AH,XX,'$'
;		.CODE

L1:
endif
		ENDM

		ASSUME	DS:NOTHING,ES:NOTHING,SS:NOTHING

START:
		MOV	AX,DGROUP
		MOV	SS,AX
		ASSUME	SS:DGROUP
		MOV	SP,OFF STACK
		MOV	DS,AX
		ASSUME	DS:DGROUP
		;
		;SHRINK MY MEMORY BLOCK
		;
		MOV	BX,SP
		MOV	CL,4
		SHR	BX,CL
		INC	BX
		ADD	BX,AX
		MOV	AX,ES
		SUB	BX,AX
		MOV	PSP,ES
		MOV	AH,4AH		;RESIZE
		INT	21H		;THAT IS THE LEAST I NEED

		JMP	MSG_EXEC

MSG_ABORT:
		PUSH	SS
		POP	DS
		LEA	DX,CANT_EXEC
		MOV	AH,9
		INT	21H

		MOV	AX,4C01H
		INT	21H

MSG_EXEC	PROC

		PUSH	SS
		POP	DS
		ASSUME	DS:DGROUP

		MOV	ES,PSP
		MOV	OPTLINKR_EXEC+4,ES

		MOV	ES,ES:[2CH]	;GET ENVIRONMENT
		XOR	DI,DI
		XOR	AX,AX
		MOV	CX,-1
2$:
		REPNZ	SCASB		;SKIP ENVIRONMENT STRINGS
		SCASB
		JNZ	2$
		INC	AX
		SCASW
		JNZ	MSG_ABORT	;SHOULDN'T HAPPEN
		PUSH	DI
		DEC	AX
		REPNE	SCASB		;FIND END OF FILENAME (SKIPPING PATH, ETC)
		DEC	DI
		DEC	DI
		MOV	AL,ES:[DI]
		CMP	AL,'E'
		JZ	21$
		CMP	AL,'e'
		JNZ	23$
21$:
		SUB	DI,4		;BACKUP OVER .EXE
		MOV	AL,ES:[DI]
23$:
		DEC	DI
		MOV	AX,ES:[DI]
		AND	AX,NOT 2020H
		CMP	AX,'KN'
		JNZ	MSG_ABORT
		MOV	AX,WPTR ES:[DI-2]
		AND	AX,NOT 2020H
		CMP	AX,'IL'
		JNZ	MSG_ABORT
		MOV	WPTR ES:[DI],'XK'
		MOV	BPTR ES:[DI-1],'N'

		POP	DX
		PUSH	ES
		POP	DS
		PUSH	SS
		POP	ES
		LEA	BX,OPTLINKR_EXEC
		MOV	AX,4B00H
		INT	21H
		JC	MSG_ABORT
		MOV	AH,4DH
		INT	21H
29$:
		MOV	AH,4CH
		INT	21H

MSG_EXEC	ENDP

		ASSUME	DS:NOTHING

if	DEBUG

HEXWOUT		PROC	NEAR
		;
		;PRINT AX
		;
		PUSH	AX
		MOV	AL,AH
		CALL	HEXOUT
		POP	AX
HEXOUT:
		PUSH	AX
		SHR	AL,1
		SHR	AL,1
		SHR	AL,1
		SHR	AL,1
		CALL	HEXNIB
		POP	AX
HEXNIB:
		AND	AL,0FH
		OR	AL,30H
		CMP	AL,'9'
		JBE	HEX_OK
		ADD	AL,7
HEX_OK:
		STOSB
		RET

HEXWOUT		ENDP

OUTBUF_OUT:
		MOV	AX,0A0DH
		STOSW
		MOV	AL,'$'
		STOSB

		LEA	DX,OUTBUF
		MOV	AH,9
		INT	21H
		RET

endif

		.DATA

		DB	' Copyright (c) Digital Mars 1994-2004 '

CANT_EXEC	DB	'Cannot EXEC LNKX.EXE',0DH,0AH,'$'

		EVEN

EMPTY_FCB	DB	11 DUP(20H),5 DUP(0)


OPTLINKR_EXEC	DW	0
		DD	80H
		DD	EMPTY_FCB
		DD	EMPTY_FCB

		.DATA?

PSP		DW	?

if	DEBUG

OUTBUF		DB	1024 DUP(?)

endif

		END	START

